package action.sbk_jjgl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import services.sbk_jjgl.CpkysServices;
import com.util.Component;
import com.PublicSystem;
import com.util.Util;
import com.syslog.SysLogServices;
/**
 * 成品卡验登记
 * @author host
 *
 */
@Controller
@RequestMapping("Cpkys.do")
public class CpkysAction {
	SysLogServices log = SysLogServices.getInstance();
	PublicSystem sys = PublicSystem.getInstance();
	CpkysServices cs = new CpkysServices();	
	/**
	* 查询批次信息
	* @author duy
	* @param request
	* @param response
	*@throws Exception
	*/ 
	@RequestMapping(params ="method=getWxk")
	public void getWxk(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String aaz001 = Component.getQuest("aaz001", request);
		String aae008 = Component.getQuest("aae008", request);
	    HashMap parms = sys.getGridSort(request);
	    String json = Util.Encode(cs.getWxk(new Object[] {aaz001, aae008}, parms));
	    String userid = Component.getSession("userid", request);
		HashMap obj = new HashMap();
		obj.put("domainid", "SBK");  //分系统号，见sys_log_bm
		obj.put("log_type", "T05");   //日志类别，见sys_log_bm
		obj.put("userid", userid); //操作人
		obj.put("rwh", Component.getSession("rwid", request));	      //任务号（菜单号），取Component.getSession("rwid", request),若特殊则为空为自定义
		obj.put("content", "制卡批次为：" + aaz001 + "的无效卡人员查询");  //日志内容，自己组合拼装
		obj.put("czqd", "Q1");	      //操作渠道，见sys_log_bm
		obj.put("czrlb", "L01");      //操作人类别，见sys_log_bm
		obj.put("datain", "制卡批次为：" + aaz001 + "银行为：" + aae008); //输入参数
		obj.put("dataout", "success");//输出参数
		log.sysLogMap(obj, request); 	
	    Component.print(json, response);
	}	
	/**
	 * 
	 */
	
	@RequestMapping(params ="method=getunitdata")
	public void getunitdata(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String id = Component.getQuest("id", request);
		String aaz001 = Component.getQuest("aaz001", request);
		HashMap user = cs.getUnitData(id,aaz001);	
		Component.print( Util.Encode(user),response);
	}
	/**
	 * 新增失效信息，未制卡人员信息，质量问题信息
	 * @author duy 
	 * @param request
	 * @param response
	 *@throws Exception
	 */
	@RequestMapping(params ="method=saveWzk")
	public void saveAZ10(HttpServletRequest request, HttpServletResponse response) throws Exception {
		   String userid = Component.getSession("userid", request);
	       String data = Component.getQuest("data", request);
	       ArrayList rows = (ArrayList<?>)Util.Decode(data);
	      /* String aae008 = request.getParameter("aae008");
	       String aaz001 = request.getParameter("aaz001");*/
	       String data3=Component.getQuest("data3", request);
	       ArrayList rows3 = (ArrayList<?>)Util.Decode(data3);
	       HashMap map3 = (HashMap)rows3.get(0);
	       
	       String aae011 = Component.getSession("userid", request);
	       HashMap m = new HashMap();
	       String sss = sys.callFunction("ZJ_GET_EVENTID", m);
	       String[] s = sss.split("&");
	       String eventid = s[0];
	       cs.insertzj_tem(map3,eventid);
	       for(int i = 0; i < rows.size(); i++) {
	    	   HashMap map = (HashMap)rows.get(i);
	    	   map.put("aae008", map3.get("aae008"));
	    	   map.put("eventid", eventid);
	    	   map.put("eventtype", "wxk");
	    	   cs.insertTmp(map);
	       }
	       String data1 = Component.getQuest("data1", request);
	       ArrayList rows1 = (ArrayList)Util.Decode(data1);
	       for(int i = 0; i < rows1.size(); i++) {
	    	   HashMap map1 = (HashMap)rows1.get(i);
	    	   map1.put("aae008", map3.get("aae008"));
	    	   map1.put("eventid", eventid);
	    	   map1.put("aac001", map1.get("aac0011"));
	    	   map1.put("aaz723", map1.get("aaz7231"));
	    	   map1.put("eventtype", "wzk");	    	  
	    	   cs.insertTmp(map1);
	       }
	       String data2=Component.getQuest("data2", request);
	       ArrayList rows2 = (ArrayList)Util.Decode(data2);
	       for(int i = 0; i < rows2.size(); i++) {
	    	   HashMap map2 = (HashMap)rows2.get(i);
	    	   map2.put("aae008", map3.get("aae008"));
	    	   map2.put("eventid", eventid);
	    	   map2.put("aac001", map2.get("aac0012"));
	    	   map2.put("aaz723", map2.get("aaz7232"));
	    	   map2.put("eventtype", "wtzk");
	    	   cs.insertTmp(map2);
	       }
	       HashMap row = new HashMap();
	       row.put("eventid", eventid);
	       row.put("aaz001", map3.get("aaz001"));
	       row.put("aae011", aae011);
	       String result = cs.insertWzk(row);
	       String result1 = "";
	       if("0".equals(result)||null == result) {
	        	result1 = "保存成功!";
	        	HashMap obj = new HashMap();
	    		obj.put("domainid", "SBK");  //分系统号，见sys_log_bm
	    		obj.put("log_type", "T03");   //日志类别，见sys_log_bm
	    		obj.put("userid", userid); //操作人
	    		obj.put("rwh", Component.getSession("rwid", request));	      //任务号（菜单号），取Component.getSession("rwid", request),若特殊则为空为自定义
	    		obj.put("content", "制卡批次为：" + row.get("aaz001").toString() + "的成品卡验收登记");  //日志内容，自己组合拼装
	    		obj.put("czqd", "Q1");	      //操作渠道，见sys_log_bm
	    		obj.put("czrlb", "L01");      //操作人类别，见sys_log_bm
	    		obj.put("datain", eventid+","+map3.get("aaz001")+","+aae011); //输入参数
	    		obj.put("dataout", result1);//输出参数
	    		log.sysLogMap(obj, request); 	
	        }
	       else {
	        	result1="保存失败:原因为" + result;
	        	HashMap obj = new HashMap();
	    		obj.put("domainid", "SBK");  //分系统号，见sys_log_bm
	    		obj.put("log_type", "T03");   //日志类别，见sys_log_bm
	    		obj.put("userid", userid); //操作人
	    		obj.put("rwh", Component.getSession("rwid", request));	      //任务号（菜单号），取Component.getSession("rwid", request),若特殊则为空为自定义
	    		obj.put("content", "制卡批次为：" + row.get("aaz001").toString() + "的成品卡验收登记");  //日志内容，自己组合拼装
	    		obj.put("czqd", "Q1");	      //操作渠道，见sys_log_bm
	    		obj.put("czrlb", "L01");      //操作人类别，见sys_log_bm
	    		obj.put("datain",  eventid+","+map3.get("aaz001")+","+aae011); //输入参数
	    		obj.put("dataout", result1);//输出参数
	    		log.sysLogMap(obj, request);
	        }
	      Component.print(result1, response);
	}	
	/**
	 * 获取下拉列表数据
	 * @author duy
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	@RequestMapping(params ="method=getselect")
	public void getSelect(HttpServletRequest request, HttpServletResponse response) throws Exception {
		List data = cs.getSelect(Component.getQuest("AAA100", request));
    	Component.print(Util.Encode(data), response);
	}	
	
	/**
	 * 获取制卡卡商
	 * @author duy
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	@RequestMapping(params ="method=getvalue")
	public void getvalue(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String aaz001=Component.getQuest("aaz001", request);
		String aae008=Component.getQuest("aae008", request);
		HashMap map = new HashMap();
		map.put("aaz001", aaz001);
		map.put("aae008", aae008);
		String result =  cs.getvalue(map);
    	Component.print(result, response);
	}
	/**
	 * 获取下拉列表数据卡厂
	 * @author duy
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	@RequestMapping(params ="method=getselectKC")
	public void getselectKC(HttpServletRequest request, HttpServletResponse response) throws Exception {
		List data = cs.getselectKC();
		Component.print(Util.Encode(data), response);
	}	
	/**
	 * 未制卡原因等下拉框选项
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	@RequestMapping(params = "method=getselectWzk")
	public void getBKLX(HttpServletRequest request, HttpServletResponse response) throws Exception {
		List data = cs.getselectWzk(Component.getQuest("AAA100", request));
		Component.print(Util.Encode(data), response);
	}		
}
